package com.base.thread.battle;

/**
 * 军队线程
 * 模拟军队作战行为
 *
 * @author innocent
 * @date 2019/1/24 11:47
 */
public class ArmyRunnable implements Runnable{

    volatile boolean keepRunning  = true;

    @Override
    public void run() {
        while (keepRunning) {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + "进攻对方" +i);
                //当前线程让出CPU，谁进攻还不一定呢
                Thread.yield();
            }
        }
        System.out.println("结束了战斗");
    }
}
